<template>
	<!-- 浦发银行 -->
	<view>
		<view class="tit">
			<image class="titBg" src="../../static/bank-icon4.png" mode="widthFix"></image>
			<view class="kanum">{{'借记卡('+list.balance.bankCode.substr(12,4)+')'}}</view>
			<view class="numtxt" style="font-family: 'jtfont-icon';">
				<view>{{list.balance.showBalance}}</view>
				<view>{{list.balance.showBalance}}</view>
			</view>
			<view class="backBtn" @tap="backBtn"></view>
		</view>
		<view class="month">本月</view>
		<view class="main" v-for="(item,index) in list.list" :key="index" @tap="delBtn" :data-id="item.id">
			<view>
				<view style="font-size: 3.8vw;color: #333333;">{{item.payTypeStr}}</view>
				<view style="font-size: 3.2vw;color: #999999;">{{new Date(item.createTime).setHours(0, 0, 0, 0)==new Date().setHours(0, 0, 0, 0)?'今天 '+item.createTime.substr(11,8):new Date(item.createTime).setHours(0, 0, 0, 0)-new Date().setHours(0, 0, 0, 0)=='-86400000'?'昨天 '+item.createTime.substr(11,8):item.createTime}}</view>
			</view>
			<view>
				<view style="font-size: 4vw;" :class="item.payType==0?'mycolor':''">{{item.payType==0?'+':'-'}}{{item.showAmount}}</view>
				<view style="font-size: 3.2vw;color: #999999;">余额：{{item.amount2}}</view>
			</view>
			<view style="font-size: 3.2vw;color: #1648cf;font-weight: bold;">❯</view>
		</view>
	</view>
</template>

<script>
	const http = require('../../utils/http.js');
	export default {
		data() {
			return {
				id:null,
				list:null,
				year:null,
				month:null
			}
		},
		onLoad(options) {
			this.id=options.id
			//console.log(new Date().getMonth()+1)
			let d = new Date('2021-04-21 12:12:12').setHours(0, 0, 0, 0);
			let today = new Date().setHours(0, 0, 0, 0);
		
			let obj = {
			  '-86400000': '昨天',
			  0: '今天',
			  86400000: '明天',
			};
			console.log(new Date('2021-04-21 12:12:12').setHours(0, 0, 0, 0))
			console.log(new Date().setHours(0, 0, 0, 0))
			console.log(obj[d - today])
			    //return obj[d - today] || '啥也不是';
		},
		onShow() {
			var now = new Date();
			this.year = now.getFullYear(); //年
			if((now.getMonth() + 1) < 10){ //月
				this.month = '0'+(now.getMonth() + 1)
			}else{
				this.month = now.getMonth() + 1;
			}
			uni.showLoading({
			    title: '加载中'
			});
			http.get('/api/balance/getBalanceDetail',{balanceId:this.id}).then(res => {
				//console.log(res.result.balance.bankCode)
				//console.log(res.result.balance.bankCode.replace(/^(\w{4})\w{10}(.*)$/, '$1***$2'))
				if (res.code == 200 && res.result) {
					this.list=res.result
				}
				uni.hideLoading();
			})
			
		},
		methods: {
			backBtn:function(){
				uni.navigateBack({
					delta: 1
				})
			},
			delBtn:function(e){
				var that=this
				uni.showModal({
				    title: '删除',
				    content: '确定删除该数据吗？',
				    success: function (res) {
				        if (res.confirm) {
				            //console.log(e.currentTarget.dataset.id);
							uni.showLoading({
							    title: '加载中'
							});
							http.get('/api/balance/delBalanceDetail',{balanceDetailId:e.currentTarget.dataset.id}).then(res => {
								uni.showToast({
								  title: res.message,
								  icon: 'none'
								});
								if(res.code==200){
									http.get('/api/balance/getBalanceDetail',{balanceId:that.id}).then(res1 => {
										if (res1.code == 200 && res1.result) {
											that.list=res1.result
										}
									})
								}
								uni.hideLoading();
							})
				        } else if (res.cancel) {
				            console.log('用户点击取消');
				        }
				    }
				});
			}
		}
	}
</script>

<style>
	page{
		color: #333333;
	}
	@font-face {
		font-family:jtfont-icon;
		src: url('~@/fonts/gsfont.otf');
	}
	.mycolor{
		color: #fe5c45;
	}
	.tit{
		position: relative;
	}
	.titBg{
		width: 100%;
	}
	.kanum{
		font-size: 3.4vw;
		position: absolute;
		top: 23vw;
		left: 16.5vw;
	}
	.backBtn{
		width: 10vw;
		height: 10vw;
		position: absolute;
		top: 6.5vw;
		left: 4vw;
	}
	.numtxt{
		width: 100%;
		position: absolute;
		top: 42vw;
		display: flex;
		flex-direction: row;
		justify-content: center;
	}
	.numtxt>view{
		width: 42%;
		text-align: center;
		font-size: 4.6vw;
		font-weight: bold;
	}
	.month{
		padding: 4vw 0;
		margin: 0 4.2vw;
		font-size: 4vw;
		font-weight: bold;
		border-bottom: 1px solid #F2F2F2;
	}
	.main{
		padding: 4vw 0;
		margin: 0 4.2vw;
		display: flex;
		justify-content: space-between;
		align-items: center;
		border-bottom: 1px solid #F2F2F2;
	}
	.main>view:nth-child(1)>view:nth-child(1),.main>view:nth-child(2)>view:nth-child(1){
		margin-bottom: 1.4vw;
	}
	.main>view:nth-child(2){
		flex: 1;
		text-align: right;
	}
	.main>view:nth-child(3){
		padding: 0 2.8vw;
	}
</style>
